package com.dayuanit.dy16.atm.util;

import java.util.Random;

public class CardUtils {

    private static final int default_length = 5;

    public static String createCardNum() {
        return randomCardNum(default_length);
    }

    public static String createCardNum(int cardLength) {
        return randomCardNum(cardLength);
    }

    public static String markCardNum(String cardNum) {
        StringBuilder sx = new StringBuilder(cardNum.length());
        sx.append(cardNum.substring(0, 1));
        sx.append("***");
        sx.append(cardNum.substring(cardNum.length() - 1, cardNum.length()));
        return sx.toString();
    }

    private static String randomCardNum(int cardLength) {
        Random random = new Random();
        StringBuilder sx = new StringBuilder(cardLength);

        for (int i=0; i<cardLength; i++) {
            int number = random.nextInt(10);
            sx.append(number);
        }
        return sx.toString();
    }

    public static void main(String[] args) {
//        for (int i=0;i<10; i++) {
//            System.out.println(createCardNum(9));
//        }

        System.out.println(markCardNum("95270"));
    }
}
